<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../../css/aui.css">
    <link rel="stylesheet" type="text/css" href="../../css/aui-slide.css">
    <link rel="stylesheet" type="text/css" href="../../css/api.css">
    <link rel="stylesheet" type="text/css" href="../../css/jquery.mobile-1.4.5.css">
    <link rel="stylesheet" type="text/css" href="../../css/friends.css">
</head>

<body>
    <header>
        <header class="aui-bar aui-bar-nav">
            <a class="aui-pull-left" onclick="api.closeWin()"><span class="aui-iconfont aui-icon-left"></span></a>
            <div class="aui-title">我的团队</div>
        </header>
        <!-- <div class="aui-searchbar" id="search">
            <div class="aui-searchbar-input aui-border-radius" style="background-color:#dedede;">
                <i class="aui-iconfont aui-icon-search"></i>
                <form action="javascript:search();" >
                    <input type="search" placeholder="搜素账号或者芒客昵称 " >
                </form>
            </div>
        </div> -->
        <div class="top">              
            <div class="box1">
                <p>共得佣金(￥)</p>
                <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id='amou'></span></p>
            </div>
            <div class="box2">
                <p>今日佣金(￥)</p>
                <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0</p>
            </div>
        </div>
        <div class="friends-top">
          <ul>
              <li>好友列表</li>
              <li>好友数量</li>
              <li>注册时间</li>
          </ul>
        </div>
        <div class="aui-content aui-margin-t-15" id="friends_list">
          
        </div>

</body>
    <script type="text/javascript" src="../../script/api.js"></script>
    <!-- <script type="text/javascript" src="../../script/jquery.min.js"></script>
    <script type="text/javascript" src="../../script/jquery.mobile-1.4.5.js"></script> -->
<script type="text/javascript">
    apiready = function() {
        var user_avater = $api.byId('user_avater');
        var friends_name = $api.byId('friends_name');
        var friends_regist_time = $api.byId('friends_regist_time');
        var friends_count = $api.byId('friends_count');
        var data = {
            token: $api.getStorage('token')
        }
        setFriends();

        function setFriends() {

            if(!$api.getStorage('token')){
                api.alert({
                    title:'提醒',
                    msg:'您还没有登录！请先登录。。。',
                    buttons:['去登陆']
                },function(ret,err){
                    if(ret.buttonIndex==1){
                        location.href = '../login.html';
                        return false;
                    }
                });
            }

          api.ajax({
              url: 'http://www.mk517.com/webApi/friends.php',
              method: 'post',
              dataType: 'json',
              "headers":{"Content-Type":"application/json"},
              data: {
                      body: data
              }
          }, function(ret, err) {

              if (ret) {

                if(ret.code==-1){
                    $api.toast('查询结果','未查询到信息',2500);
                    $api.setStorage('token',''); //重置token
                    return false;
                }
                  var amou = 0;
                  for (var i = 0; i < ret.length; i++) {
                      var data = ret[i];
                      amou += data['amou'];
                      $api.byId('friends_list').innerHTML += '<ul class="aui-list aui-media-list">' +
                          '<li class="aui-list-item aui-list-item-middle">' +
                          '<div class="aui-media-list-item-inner">' +
                          '<div class="aui-card-list-user-avatar">' +
                          '<img id="post_user_avater" src="' + data.user_avater + '" class="aui-img-round" /></div>' +
                          '<div class="aui-list-item-inner">' +
                          '<div class="aui-list-item-text">' +
                          '<div class="aui-list-item-title aui-font-size-14" id="friends_name">' + data.friends_name + '</div>' +
                          '<div class="aui-label aui-label-outlined" id="friends_count"><i class="aui-iconfont aui-icon-my"></i>' + data.friends_count + '人</div>' +
                          '<div class="aui-list-item-right" id="friends_regist-time">' + data.friends_regist_time + '</div></div>' +
                          '</div></div></li></ul>';
                  }
                  $api.byId('amou').innerHTML = amou;


              } else {
                $api.toast(
                  '暂无好友'
                );
              }
          });

        }


    }
</script>

</html>
